package excollection;

import java.util.ArrayList;
import java.util.Vector;

/**
 * @author: knowno
 * @create: 2025-09-15 11:02
 * @Version 1.0
 **/
public class TestVector {
    public static void main(String[] args) {

        //Vector =>和ArrayList的区别
        //线程安全
        //效率低
        Vector vector1 = new Vector();

        //添加元素
        vector1.add("hello");
        vector1.add("world");
        vector1.add("java");

        //打印集合
        System.out.println(vector1);

        //获取元素
        System.out.println(vector1.get(0));

        //删除元素
        vector1.remove(0);
        System.out.println(vector1);

        //集合的大小
        System.out.println(vector1.size());

        //遍历集合
        for (int i = 0; i < vector1.size(); i++) {
            System.out.println(vector1.get(i));
        }

        //增强for循环遍历集合
        for (Object o : vector1) {
            System.out.println(o);
        }

        //集合的清空
        vector1.clear();
        System.out.println(vector1);

        //判断集合是否为空
        System.out.println(vector1.isEmpty());

        //判断集合是否包含某个元素
        System.out.println(vector1.contains("hello"));



    }
}
